const {dialog} = require('electron').remote;
const fontreconv = require('./app/fontreconv');
var path = require('path');

var tools_path;

//obj file to drc
function objFile2Drc(onDone) {
    let conv = new fontreconv();
    dialog.showOpenDialog({title: "obj file", filters: [{name: 'obj 3d models', extensions: ['obj']}], properties: ['openFile']},
    function(filenames) {
      conv.convObjFile2Drc(filenames[0], function() {
            console.log("done done done!!!");
        if (onDone) {
                onDone();
        }
        });
    });
}

//obj dir to drc
function objDir2Drc(onDone) {
    let conv = new fontreconv();
    dialog.showOpenDialog({title: "obj files directory", properties: ['openDirectory']},
    function(filenames) {
        let dir = filenames[0];
      conv.convObjDir2Drc(dir, function() {
            console.log("done done done!!!");
        if (onDone) {
                onDone();
        }
        });
    });
}

//obj dir to ftrm
function objDir2Ftrm(onDone) {
    let conv = new fontreconv();
    dialog.showOpenDialog({title: "obj files directory", properties: ['openDirectory']},
    function(filenames) {
        let dir = filenames[0];
      conv.convObjDir2Drc(dir, function() {
        conv.packDrcDir(dir, function() {
                console.log("done done done!!!");
          if (onDone) {
                    onDone();
          }
            });
        });
    });
}

//json file to ftrn
function jsonFile2Ftrn(onDone) {
    let conv = new fontreconv();
    dialog.showOpenDialog({title: "json file", filters: [{name: 'Json', extensions: ['json']}], properties: ['openFile']},
    function(filenames) {
        let dir = filenames[0];
      conv.confuseJsonFile(dir, function() {
            console.log("done done done!!!");
        if (onDone) {
                onDone();
        }
        });
    });
}

//json dir to ftrn
function jsonDir2Ftrm(onDone) {
    let conv = new fontreconv();
    dialog.showOpenDialog({title: "json files directory", properties: ['openDirectory']},
    function(filenames) {
        let dir = filenames[0];
      conv.confuseJsonDir(dir, function() {
            console.log("done done done!!!");
        if (onDone) {
                onDone();
        }
        });
    });
    }
function ftrnFile2Json(onDone) {
    let conv = new fontreconv();
    dialog.showOpenDialog({title: "FTRN file", filters: [{name: 'Ftrn', extensions: ['ftrn']}], properties: ['openFile']},
        function(filenames) {
            let dir = filenames[0];
            conv.decodeFtrnFile(dir, function() {
                console.log("done done done!!!");
                if (onDone) {
                    onDone();
                }
            });
        });
}

function initTools(onDone) {
    tools_path = path.join('draco_encoder');
    path.normalize(tools_path);
    if (onDone) {
        onDone(tools_path);
    }
}

function selectTools(onDone) {
    let conv = new fontreconv();

    dialog.showOpenDialog({title: "tool file", properties: ['openFile']},

        function(filenames) {
            tools_path = filenames[0];
            path.normalize(tools_path);
            console.log(tools_path)
            if (onDone) {
                onDone(tools_path);
            }
     });
}


